package com.ddzh.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ddzh.pojo.Menu;
import com.ddzh.vo.MenuVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface MenuMapper extends BaseMapper<Menu> {
    @Select("select * from menu")
    List<MenuVo> findAllMenu();

    @Select("select mt.path\n" +
            "from role_menu_t rmt left join menu_t mt on rmt.menu_id=mt.id\n" +
            "where rmt.role_id=#{roleId}")
    List<String> findMenuPathByURoleId(@Param("roleId") Long roleId);

    @Select("SELECT distinct m.*\n" +
            "FROM user_t u \n" +
            "LEFT JOIN user_role_t ur ON u.id = ur.user_id\n" +
            "LEFT JOIN role_menu_t rm ON ur.role_id = rm.role_id\n" +
            "LEFT JOIN menu_t m ON m.id = rm.menu_id\n" +
            "WHERE u.username = #{username}")
    List<MenuVo> getUserMenuTrees(String currentUser);
}
